﻿using ScottPlot;
using ScottPlot.Plottables;
using ScottPlot.WPF;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace WpfApp_MvvmPatten.Base;

public class ScottPlotExtension
{

    public static ObservableCollection<double> GetValues(DependencyObject obj)
    {
        return (ObservableCollection<double>)obj.GetValue(ValuesProperty);
    }

    public static void SetValues(DependencyObject obj, ObservableCollection<double> value)
    {
        obj.SetValue(ValuesProperty, value);
    }

    public static readonly DependencyProperty ValuesProperty =
        DependencyProperty.RegisterAttached("Values", typeof(ObservableCollection<double>), typeof(ScottPlotExtension), new PropertyMetadata(null,new PropertyChangedCallback(ValuesPropertyChangeEvent)));


    public static void ValuesPropertyChangeEvent(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        ObservableCollection<double> datas = (ObservableCollection<double>)e.NewValue;
        WpfPlot wpfPlot = (WpfPlot)d;
        Signal signal = wpfPlot.Plot.Add.Signal(datas);
        wpfPlot.Refresh();

        datas.CollectionChanged += (s, e) => 
        {
            if (e.Action == NotifyCollectionChangedAction.Add)
            {

                //wpfPlot.Plot.Add.si((s as ObservableCollection<double>).ToArray());


                wpfPlot.Refresh();
            }
        };

    }

    private static void Datas_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
    {
        throw new NotImplementedException();
    }
}
